<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    function* fibonacci() {
      let [prev,curr] = [0,1];
      for(;;) {
        yield curr;
        [prev,curr] = [curr,prev + curr];
      }
    }
    // let i = 0;
    for(let n of fibonacci()) {
      if(n > 1000) break;
      // if(i == 5) {
      //   break;
      // }
      // i++;
      console.log(n);
    }
    //斐波那契数列，n是累加到多少
    //而想要输出几次，除了可以用全局变量来控制for...of，还可以循环调用几次next()方法
  </script>
</body>

</html>